package pub.tbc.api.service.mapping;

import io.netty.handler.codec.http.FullHttpRequest;
import lombok.extern.slf4j.Slf4j;
import pub.tbc.api.helper.ServiceHelper;
import pub.tbc.api.service.ServiceInfo;
import pub.tbc.api.service.ServiceConfigTable;

/**
 * 根据本地配置信息获取服务信息<br>
 *
 * @author tbc on 2017/3/22 12:53:36.
 */
@Slf4j
public class NativeConfigServiceMapping implements ServiceMapping {
    private ServiceConfigTable mapTable = ServiceConfigTable.getInstance();


    /**
     * 先按服务名
     *
     * @param request Netty封装的http请求对象
     * @return 服务信息对象
     */
    @Override
    public ServiceInfo map(FullHttpRequest request) {
        String serviceName = ServiceHelper.getServiceNameByUri(request.uri());
        if (mapTable.contain(serviceName))
            return mapTable.getServiceInfo(serviceName);
        return ServiceInfo.defaultServiceInfo(request);
    }
}
